package com.wpzf.ndhc.service.impl;

import com.wpzf.ndhc.utils.TableUtil;
import com.wpzf.ndhc.mapper.WpzfNdhcThTaskMapper;
import com.wpzf.ndhc.service.WpzfNdhcThTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class WpzfNdhcThTaskServiceImpl implements WpzfNdhcThTaskService {

    @Autowired
    WpzfNdhcThTaskMapper wpzfNdhcThTaskMapper;

    @Override
    public Integer dwThSubmit(Map<String, Object> parms) {
        parms = TableUtil.TableName(parms);
        Integer rest = 0;
        if ("1".equals(parms.get("state"))) {
            List<String> xzqdmList = (List<String>) parms.get("xzqdmList");
            if (xzqdmList != null) {
                for (String xzqdm : xzqdmList) {
                    parms.put("xzqdm", xzqdm);
                    wpzfNdhcThTaskMapper.delJlTbjg(parms);
                    wpzfNdhcThTaskMapper.delJlHcrwfp(parms);
                    Integer i = wpzfNdhcThTaskMapper.updateDwTjState(parms);
                    if (i > 0) {
                        rest += wpzfNdhcThTaskMapper.dwThSubmit(parms);
                    }
                }
            }
        } else if ("0".equals(parms.get("state"))) {
            List<String> xzqdmList = (List<String>) parms.get("xzqdmList");
            if (xzqdmList != null) {
                for (String xzqdm : xzqdmList) {
                    parms.put("xzqdm", xzqdm);
                    rest += wpzfNdhcThTaskMapper.dwThSubmit(parms);
                }
            }
        }
        return rest;
    }

    @Override
    public List<Map<String, Object>> dwThTask(Map<String, Object> parms) {
        parms = TableUtil.TableName(parms);
        return wpzfNdhcThTaskMapper.dwThTask(parms);
    }

    @Override
    public List<Map<String, Object>> dwPch(Map<String, Object> parms) {
        parms = TableUtil.TableName(parms);
        return wpzfNdhcThTaskMapper.dwPch(parms);
    }

    @Override
    public Integer dwThTaskCount(Map<String, Object> parms) {
        parms = TableUtil.TableName(parms);
        return wpzfNdhcThTaskMapper.dwThTaskCount(parms);
    }

    @Override
    public Integer jlThSubmit(Map<String, Object> parms) {
        parms = TableUtil.TableName(parms);
        Integer rest = 0;
        List<Map<String, Object>> data = (List<Map<String, Object>>) parms.get("data");
        if (data != null) {
            for (Map<String, Object> map : data) {
                parms.put("tbbh", map.get("tbbh"));
                parms.put("xzqdm", map.get("xzqdm"));
                rest += wpzfNdhcThTaskMapper.jlThSubmit(parms);
            }
        }
        return rest;
    }

    @Override
    public List<Map<String, Object>> jlThTask(Map<String, Object> parms) {
        parms = TableUtil.TableName(parms);
        return wpzfNdhcThTaskMapper.jlThTask(parms);
    }

    @Override
    public Integer jlThTaskCount(Map<String, Object> parms) {
        parms = TableUtil.TableName(parms);
        return wpzfNdhcThTaskMapper.jlThTaskCount(parms);
    }

    @Override
    public List<Map<String, Object>> dwApplyPch(Map<String, Object> parms) {
        parms = TableUtil.TableName(parms);
        return wpzfNdhcThTaskMapper.dwApplyPch(parms);
    }

    @Override
    public List<Map<String, Object>> dwApplySheng(Map<String, Object> parms) {
        parms = TableUtil.TableName(parms);
        return wpzfNdhcThTaskMapper.dwApplySheng(parms);
    }

    @Override
    public List<Map<String, Object>> dwApplyXian(Map<String, Object> parms) {
        parms = TableUtil.TableName(parms);
        return wpzfNdhcThTaskMapper.dwApplyXian(parms);
    }

    @Override
    public List<Map<String, Object>> dwApply(Map<String, Object> parms) {
        parms = TableUtil.TableName(parms);
        return wpzfNdhcThTaskMapper.dwApply(parms);
    }

    @Override
    public Integer dwApplyCount(Map<String, Object> parms) {
        parms = TableUtil.TableName(parms);
        return wpzfNdhcThTaskMapper.dwApplyCount(parms);
    }

    @Override
    public Integer dwApplySh(Map<String, Object> parms) {
        parms = TableUtil.TableName(parms);
        Integer rest = 0;
        List<Map<String, Object>> xzqdmList = (List<Map<String, Object>>) parms.get("xzqdmList");
        if (xzqdmList != null) {
            for (Map<String, Object> map : xzqdmList) {
                parms.put("xzqdm", map.get("xzqdm"));
                if ("0".equals(parms.get("sftg"))) {
                    wpzfNdhcThTaskMapper.updateDwTjState(parms);
                }
                rest += wpzfNdhcThTaskMapper.dwApplySh(parms);
            }
        }
        return rest;
    }

    @Override
    public List<Map<String, Object>> jlApplyPch(Map<String, Object> parms) {
        parms = TableUtil.TableName(parms);
        return wpzfNdhcThTaskMapper.jlApplyPch(parms);
    }

    @Override
    public List<Map<String, Object>> jlApplySheng(Map<String, Object> parms) {
        parms = TableUtil.TableName(parms);
        return wpzfNdhcThTaskMapper.jlApplySheng(parms);
    }

    @Override
    public List<Map<String, Object>> jlApplyXian(Map<String, Object> parms) {
        parms = TableUtil.TableName(parms);
        return wpzfNdhcThTaskMapper.jlApplyXian(parms);
    }

    @Override
    public List<Map<String, Object>> jlApply(Map<String, Object> parms) {
        parms = TableUtil.TableName(parms);
        return wpzfNdhcThTaskMapper.jlApply(parms);
    }

    @Override
    public Integer jlApplyCount(Map<String, Object> parms) {
        parms = TableUtil.TableName(parms);
        return wpzfNdhcThTaskMapper.jlApplyCount(parms);
    }

    @Override
    public Integer jlApplySh(Map<String, Object> parms) {
        parms = TableUtil.TableName(parms);
        Integer rest = 0;
        List<Map<String, Object>> data = (List<Map<String, Object>>) parms.get("data");
        if (data != null) {
            for (Map<String, Object> map : data) {
                parms.put("tbbh", map.get("tbbh"));
                parms.put("xzqdm", map.get("xzqdm"));
                if ("0".equals(parms.get("sftg"))) {
                    wpzfNdhcThTaskMapper.updateJlTjState(parms);
                }
                rest += wpzfNdhcThTaskMapper.jlApplySh(parms);
            }
        }
        return rest;
    }

    @Override
    public List<Map<String, Object>> jlFzrThTask(Map<String, Object> parms) {
        parms = TableUtil.TableName(parms);
        return wpzfNdhcThTaskMapper.jlFzrThTask(parms);
    }

    @Override
    public Integer jlFzrThTaskCount(Map<String, Object> parms) {
        parms = TableUtil.TableName(parms);
        return wpzfNdhcThTaskMapper.jlFzrThTaskCount(parms);
    }

    @Override
    public List<Map<String, Object>> getPch(Map<String, Object> parms) {
        parms = TableUtil.TableName(parms);
        return wpzfNdhcThTaskMapper.getPch(parms);
    }

    @Override
    public List<Map<String, Object>> getSheng(Map<String, Object> parms) {
        parms = TableUtil.TableName(parms);
        return wpzfNdhcThTaskMapper.getSheng(parms);
    }

    @Override
    public List<Map<String, Object>> getXzq(Map<String, Object> parms) {
        parms = TableUtil.TableName(parms);
        List<Map<String, Object>> xzqList = wpzfNdhcThTaskMapper.getXzq(parms);
        if (xzqList != null) {
            for (Map<String, Object> xzqData : xzqList) {
                StringBuilder jl_shr = new StringBuilder();
                List<Map<String, Object>> jlLisf = wpzfNdhcThTaskMapper.getXzqFpjl(xzqData);
                if (jlLisf != null) {
                    for (Map<String, Object> map : jlLisf) {
                        if (jl_shr.length() > 0) {
                            jl_shr.append(map.get(","));
                        }
                        jl_shr.append(map.get("jl_shr"));
                    }
                }
                xzqData.put("jl_shr", jl_shr.toString());
            }
        }
        return xzqList;
    }

    @Override
    public List<Map<String, Object>> queryXzq(Map<String, Object> parms) {
        parms = TableUtil.TableName(parms);
        return wpzfNdhcThTaskMapper.queryXzq(parms);
    }
}
